import Vue from 'vue'
import VueRouter from 'vue-router'
const Header = () => import('../views/Header.vue');
const Footer = () => import ('../views/Footer.vue');
const Home = () => import ('../views/Home.vue');
const Login = () => import('../views/Login.vue');
const Register = () => import('../views/Register.vue');
const Search = () => import('../views/Search.vue');
const Detail = () => import('../views/Detail.vue');
const ShoppingCart = () => import('../views/ShoppingCart.vue');
const Settlement = () => import('../views/Settlement.vue');
const Order = () => import('../views/Order.vue');
const Evaluate = () => import('../views/Evaluate.vue');
const Person = () => import('../views/Person.vue');
const PersonData = () => import('../views/PersonData.vue');
const PersonAddress = () => import('../views/PersonAddress.vue');
const PersonOrder = () => import('../views/PersonOrder.vue');
const PersonRelease = () => import('../views/PersonRelease.vue');
const PersonWant = () => import('../views/PersonWant.vue');
const PersonCollect = () => import('../views/PersonCollect.vue');
const ReleaseProduct = () => import('../views/ReleaseProduct.vue');
const ReleaseWant = () => import('../views/ReleaseWant.vue');
const Want = () => import('../views/Want.vue');
const About = () => import('../views/About.vue');
const BuyingProcess = () => import('../views/BuyingProcess.vue');
const QualitySecond = () => import('../views/QualitySecond.vue');
const Manage = () => import('../views/Manage.vue');


Vue.use(VueRouter)

const routes = [
    { path: '/', components: { default: Home, 'header': Header, 'footer': Footer } },
    { path: '/manage', components: { default: Manage, 'header': null, 'footer': null } },
    { path: '/login', components: { default: Login, 'header': null, 'footer': null } },
    { path: '/register', components: { default: Register, 'header': null, 'footer': null } },
    { path: '/search', components: { default: Search, 'header': Header, 'footer': Footer } },
    { path: '/detail', components: { default: Detail, 'header': Header, 'footer': Footer } },
    { path: '/shoppingCart', components: { default: ShoppingCart, 'header': Header, 'footer': Footer } },
    { path: '/settlement', components: { default: Settlement, 'header': Header, 'footer': Footer } },
    { path: '/order', components: { default: Order, 'header': Header, 'footer': Footer } },
    { path: '/evaluate', components: { default: Evaluate, 'header': Header, 'footer': Footer } },
    {
        path: '/person',
        components: {
            default: Person,
            'header': Header,
            'footer': Footer,
        },
        children: [
            { path: '', component: PersonData },
            { path: 'personAddress', component: PersonAddress },
            { path: 'personCollect', component: PersonCollect },
            { path: 'personOrder', component: PersonOrder },
            { path: 'personRelease', component: PersonRelease },
            { path: 'personWant', component: PersonWant },

        ]
    },
    { path: '/releaseProduct', components: { default: ReleaseProduct, 'header': Header, 'footer': Footer } },
    { path: '/releaseWant', components: { default: ReleaseWant, 'header': Header, 'footer': Footer } },
    { path: '/want', components: { default: Want, 'header': Header, 'footer': Footer } },
    { path: '/about', components: { default: About, 'header': Header, 'footer': Footer } },
    { path: '/buyingProcess', components: { default: BuyingProcess, 'header': Header, 'footer': Footer } },
    { path: '/qualitySecond', components: { default: QualitySecond, 'header': Header, 'footer': Footer } },
]

const router = new VueRouter({
    routes,
    mode: 'history'
})

router.beforeEach((to, from, next) => {
    if(to.path=="/manage"&&from.path!="/login"||to.path=="/about"){
        next("/");
    }else{
        next();
    }
})
export default router